package com.weiyi.controller.biz;

import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.weiyi.common.annotation.Log;
import com.weiyi.common.enums.BusinessType;
import com.weiyi.biz.domain.WeiyiLog;
import com.weiyi.biz.service.IWeiyiLogService;
import com.weiyi.common.core.controller.BaseController;
import com.weiyi.common.core.domain.AjaxResult;
import com.weiyi.common.utils.poi.ExcelUtil;
import com.weiyi.common.core.page.TableDataInfo;

/**
 * 位移日志Controller
 *
 * @author gq
 * @date 2020-08-31
 */
@Controller
@RequestMapping("/biz/log")
public class WeiyiLogController extends BaseController
{
    private String prefix = "biz/log";

    @Autowired
    private IWeiyiLogService weiyiLogService;

    @RequiresPermissions("biz:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询位移日志列表
     */
    @RequiresPermissions("biz:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WeiyiLog weiyiLog)
    {
        startPage();
        List<WeiyiLog> list = weiyiLogService.selectWeiyiLogList(weiyiLog);
        return getDataTable(list);
    }

    /**
     * 导出位移日志列表
     */
    @RequiresPermissions("biz:log:export")
    @Log(title = "位移日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WeiyiLog weiyiLog)
    {
        List<WeiyiLog> list = weiyiLogService.selectWeiyiLogList(weiyiLog);
        ExcelUtil<WeiyiLog> util = new ExcelUtil<WeiyiLog>(WeiyiLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 新增位移日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存位移日志
     */
    @RequiresPermissions("biz:log:add")
    @Log(title = "位移日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WeiyiLog weiyiLog)
    {
        return toAjax(weiyiLogService.insertWeiyiLog(weiyiLog));
    }

    /**
     * 修改位移日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long ID, ModelMap mmap)
    {
        WeiyiLog weiyiLog = weiyiLogService.selectWeiyiLogById(ID);
        mmap.put("weiyiLog", weiyiLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存位移日志
     */
    @RequiresPermissions("biz:log:edit")
    @Log(title = "位移日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WeiyiLog weiyiLog)
    {
        return toAjax(weiyiLogService.updateWeiyiLog(weiyiLog));
    }

    /**
     * 删除位移日志
     */
    @RequiresPermissions("biz:log:remove")
    @Log(title = "位移日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(weiyiLogService.deleteWeiyiLogByIds(ids));
    }

}
